package tree

import "fmt"

func (node *Node) Traverse()  {
	//if node == nil {
	//	return
	//}
	//node.Left.Traverse()
	//node.Print()
	//node.Rigth.Traverse()

	node.TraverseFunc(func(n *Node) {
		n.Print()
	})
	fmt.Println()
}

func (node *Node) TraverseFunc (f func(*Node)){
	if node == nil {
		return
	}
	node.Left.TraverseFunc(f)
	f(node)
	node.Rigth.TraverseFunc(f)
}

func (node * Node) TraverseWithChannel() chan *Node{

	out := make(chan  * Node)
	go func() {
		node.TraverseFunc(func(n *Node) {
			out <- n
		})
		close(out)
	}()
	return out
}